home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / biblio / bibtex / contrib / phppcf.bst < prev    next >
Lisp/Scheme  |  1992-07-19  |  66KB  |  2,010 lines

  1. % BibTeX styles for various physics journals (27-Feb-1990).
  2. % This file, physics.btx, is based on the file btxbst.doc.
  3.     % Please notify Charles Karney (Karney@Princeton.EDU)
  4.     % of any bugs, improvements, etc.
  5. % Run this file through cpp to get specific versions.  I have written
  6. % a version of cpp within Emacs.  To access it put
  7. %    (autoload 'cpp "tex$bibtex:cpp"        ; Use cpp for BibTeX styles
  8. %          "C preprocessor"
  9. %          t)
  10. % into your .emacs file.  Read in this file with
  11. %    emacs tex$bibtex:physics.btx
  12. % and run cpp with e.g.,
  13. %    M-x cpp <ret> aip <ret>
  14. % Save the resulting file to tex$latex:aip.bst.
  15. % To accomodate the variations we need (in addition to the definitions below)
  16. %    ATIT_SUPPRESS:    do not include the titles of journal articles
  17. %    NAME_INVERT:    put the initials last
  18. %    NAME_UPPER:    convert names to all caps.
  19. %    MONTH_SUPPRESS:    do not include months in journal articles
  20. %    PAREN_DATE:    dates go in parens in journal articles
  21. %    DATE_FIRST:    dates go before page numbers
  22. %    VOLUME_SPACE:    volume set off with space (not colon)
  23. %    NUM_SUPPRESS:    do not include numbers in journal articles
  24. %    BOLD_VOL:    volume numbers in bold face in journal articles
  25. %    BRACKET_NOTE:    notes in brackets
  26. %    PAGE_START_J:    include only starting page for journal articles
  27. %    PAGE_START_O:    include only starting page for other entries
  28. %    PAGE_ABBREV:    abbreviate page to p. and pages to pp.
  29. %    PHYSICS_JOUR:    include abbreviations for Physics journals
  30. %    COMMA_DELIMIT:    use comma (instead of period) to divide a citation
  31. %    NOTE_SUPPRESS:    suppress the note
  32. %    MAX_NAMES:    max number of authors before using et al (0 = infinity)
  33. %    MIN_NAMES:    number of authors to list with et al.
  34. %    EDIT_VAR:    use "edited by ..." instead of "..., editors"
  35. %    RMP_LABELS:    create RMP-style labels
  36. %    KEY_CITE:    use key as label
  37. %    NAMED_REFS:    use (Smith, 1988) style of citations
  38. %    CSC_NAMES:    names set in caps and small caps
  39. %    JOUR_DEEMPH:    don't emphasize journal name
  40. %    ETAL_EMPH:    emphasize et al.
  41. %    ALT_INCOLL    alternate ordering of fields in incollections
  42. % These are all boolean (0 or 1) except for MAX_NAMES and MIN_NAMES.
  43. % These need to satisfy 0 <= MIN_NAMES <= MAX_NAMES.
  44. % The rule here is that if all these are defined to be zero, we revert to
  45. % the standard styles.  For that reason we initialize them all to 0.
  46. % These are the original macros
  47.     % A physics version of APALIKE
  48. % This is the start of btxbst.doc
  49. % BibTeX `plain' family
  50.     % version 0.99b for BibTeX versions 0.99a or later, LaTeX version 2.09.
  51.     % Copyright (C) 1985, all rights reserved.
  52.     % Copying of this file is authorized only if either
  53.     % (1) you make absolutely no changes to your copy, including name, or
  54.     % (2) if you do make changes, you name it something other than
  55.     % btxbst.doc, plain.bst, unsrt.bst, alpha.bst, and abbrv.bst.
  56.     % This restriction helps ensure that all standard styles are identical.
  57.     % The file btxbst.doc has the documentation for this style.
  58. % BibTeX `apalike' bibliography style (24-Jan-88 version)
  59. % Adapted from the `alpha' style, version 0.99a; for BibTeX version 0.99a.
  60. % Copyright (C) 1988, all rights reserved.
  61. % Copying of this file is allowed, provided that if you make any changes at all
  62. % you name it something other than `apalike.bst'.
  63. % This restriction helps ensure that all copies are identical.
  64. % Differences between this style and `alpha' are generally heralded by a `%'.
  65. % The file btxbst.doc has the documentation for alpha.bst.
  66. %
  67. % This style should be used with the `apalike' LaTeX style (apalike.sty).
  68. % \cite's come out like "(Jones, 1986)" in the text but there are no labels
  69. % in the bibliography, and something like "(1986)" comes out immediately
  70. % after the author.  Author (and editor) names appear as last name, comma,
  71. % initials.  A `year' field is required for every entry, and so is either
  72. % an author (or in some cases, an editor) field or a key field.
  73. %
  74. % Editorial note:
  75. % Many journals require a style like `apalike', but I strongly, strongly,
  76. % strongly recommend that you not use it if you have a choice---use something
  77. % like `plain' instead.  Mary-Claire van Leunen (A Handbook for Scholars,
  78. % Knopf, 1979) argues convincingly that a style like `plain' encourages better
  79. % writing than one like `apalike'.  Furthermore the strongest arguments for
  80. % using an author-date style like `apalike'---that it's "the most practical"
  81. % (The Chicago Manual of Style, University of Chicago Press, thirteenth
  82. % edition, 1982, pages 400--401)---fall flat on their face with the new
  83. % computer-typesetting technology.  For instance page 401 anachronistically
  84. % states "The chief disadvantage of [a style like `plain'] is that additions
  85. % or deletions cannot be made after the manuscript is typed without changing
  86. % numbers in both text references and list."  LaTeX sidesteps the disadvantage.
  87. %
  88. % History:
  89. %   15-sep-86    (SK,OP)    Original version, by Susan King and Oren Patashnik.
  90. %   10-nov-86    (OP)    Truncated the sort.key$ string to the correct length
  91. %            in bib.sort.order to eliminate error message.
  92. %   24-jan-88    (OP)    Updated for BibTeX version 0.99a, from alpha.bst 0.99a;
  93. %            apalike now sorts by author, then year, then title;
  94. %            THIS `apalike' VERSION DOES NOT WORK WITH BIBTEX 0.98i.
  95. % Please notify Oren Patashnik (PATASHNIK@SCORE.STANFORD.EDU) of any bugs in
  96. % these standard styles or in this documentation file.
  97. %
  98. % This is file btxbxt.doc; it helps document bibliography styles,
  99. % and is also a template file that you can use to make
  100. % several different style files, if you have access to a C preprocessor.
  101. % For example, the standard styles were made by doing something like
  102. %    cpp -P -DPLAIN btxbst.doc plain.txt
  103. %    cpp -P -DUNSRT btxbst.doc unsrt.txt
  104. %    cpp -P -DALPHA btxbst.doc alpha.txt
  105. %    cpp -P -DABBRV btxbst.doc abbrv.txt
  106. % and then renaming after removing unwanted comments and blank lines.
  107. % If you don't have access,
  108. % you can edit this file by hand to imitate the preprocessor,
  109. % with the following explanation of the C preprocessor constructs used here.
  110. %
  111. % The output of the preprocessor is the same as the input, except that certain
  112. % lines will be excluded (and some blank lines will be added).  The sequence
  113. %    #if VAR
  114. %        lines to be included when VAR is not zero
  115. %    #else
  116. %        lines to be included when VAR is zero
  117. %    #endif
  118. % (with the #-signs appearing in column 1) means that one set or the other of
  119. % the lines are to be included depending on the value of VAR.
  120. % The #else part is optional.  Comments can be added after #else and #endif.
  121. % Variables can be set by
  122. %    #define VAR value
  123. % and one can also use #ifdef VAR to see if VAR has any value, and #ifndef
  124. % to see if it has none.
  125. % Another #if form used in this file is #if !VAR, which includes the lines
  126. % after the #if only if VAR is zero.
  127. %
  128. % Convention: Use all uppercase identifiers for these preprocessor variables
  129. % so you can spot them easily
  130. %
  131. % The command line to the preprocessor should define one of PLAIN, UNSRT, ALPHA
  132. % or ABBRV (though PLAIN will be used by default if none is given),
  133. % and the following lines will set various boolean variables to control the
  134. % various lines that are chosen from the rest of the file.
  135. % Each boolean variable should be set true (1) or false (0) in each style.
  136. % Here are the current variables, and their meanings:
  137. %    1:    an alphabetic label is used (if false then a numeric
  138. %                label is used)
  139. %    1:        the entries should be sorted by label (if nonnumeric)
  140. %                and other info, like authors (if false, then
  141. %                entries remain in order of occurrence)
  142. %    0:    the authors, editors, etc., get the full names as
  143. %                given in the bibliography file (if false, the first
  144. %                names become initials)
  145. %    0:    titles of non-"books" (e.g., articles) should be
  146. %                converted to lower-case, except the first letter or
  147. %                first letter after a colon
  148. %                (if false then they appear as in the database)
  149. %    1:    months are spelled out in full (if false, then
  150. %                they're abbreviated)
  151. %    0:    macro journal names are spelled out in full
  152. %                (if false then they are abbreviated, currently
  153. %                as they appear in ACM publications)
  154. %#        define PLAIN 1
  155. %
  156. %   Entry formatting: Similar to that recommended by Mary-Claire van Leunen
  157. %    in "A Handbook for Scholars".  Book-like titles are italicized
  158. %    (emphasized) and non-book titles are converted to sentence
  159. %    capitilization (and not enclosed in quotes).
  160. %    This file outputs a \newblock between major blocks of an entry
  161. %    (the name \newblock is analogous to the names \newline and \newpage)
  162. %    so that the user can obtain an "open" format, which has a line break
  163. %    before each block and lines after the first are indented within blocks,
  164. %    by giving the optional \documentstyle argument `openbib';
  165. %    The default is the "closed" format---blocks runs together.
  166. %
  167. %   Citation alphabetic label format:
  168. %        [Knu73] for single author (or editor or key)
  169. %        [AHU83] (first letters of last names) for multiple authors
  170. %
  171. %   Citation label numberic format:
  172. %        [number]
  173. %
  174. %   Reference list ordering for sorted, alphabetic lables:
  175. %        alphabetical by citation label, then by author(s) or whatever
  176. %        passes for author in the absence of one, then by year,
  177. %        then title
  178. %
  179. %   Reference list ordering for sorted, numeric lables:
  180. %        alphabetical by author(s) or whatever passes
  181. %        for author in the absence of one, then by year, then title
  182. %
  183. %   Reference list ordering for unsorted:
  184. %        by the order cited in the text
  185. %
  186. %   History
  187. %   12/16/84    (HWT)    Original `plain' version, by Howard Trickey.
  188. %   12/23/84    (LL)    Some comments made by Leslie Lamport.
  189. %    2/16/85    (OP)    Changes based on LL's comments, Oren Patashnik.
  190. %    2/17/85    (HWT)    Template file and other standard styles made.
  191. %    3/28/85    (OP)    First release, version 0.98b for BibTeX 0.98f.
  192. %    5/ 9/85    (OP)    Version 0.98c for BibTeX 0.98i:
  193. %            fixed Theoretical Computer Science macro name;
  194. %            fixed the format.vol.num.pages function.
  195. %    1/24/88    (OP)    Version 0.99a for BibTeX 0.99a, main changes:
  196. %            assignment operator (:=) arguments reversed;
  197. %            the preamble$ function outputs the database PREAMBLE;
  198. %            entry.max$ and global.max$ (built-in) variables replace
  199. %            entry.string.max and global.string.max functions;
  200. %            alphabetizing by year then title, not just title;
  201. %            many unnecessary ties removed; \it ==> \em;
  202. %            the `alpha' style uses a superscripted `+' instead of a
  203. %            `*' for unnamed names in constructing the label;
  204. %            the `abbrv' style now uses "Mar." and "Sept.";
  205. %            the functions calc.label and presort now look at just
  206. %            the fields they're supposed to;
  207. %            BOOKLET, MASTERSTHESIS, TECHREPORT use nonbook titles;
  208. %            INBOOK and INCOLLECTION take an optional type (e.g.
  209. %            type = "Section"), overriding the default "chapter";
  210. %            BOOK, INBOOK, INCOLLECTION, and PROCEEDINGS now allow
  211. %            either volume or number, not just volume;
  212. %            INCOLLECTION now allows an edition and series field;
  213. %            PROCEEDINGS and INPROCEEDINGS now use the address field
  214. %            to tell where a conference was held;
  215. %            INPROCEEDINGS and PROCEEDINGS now allow either volume
  216. %            or number, and also a series field;
  217. %            MASTERSTHESIS and PHDTHESIS accept types other than
  218. %            "Master's thesis" and "PhD thesis";
  219. %            UNPUBLISHED now outputs, in one block, note then date;
  220. %            MANUAL now prints out the organization in
  221. %            the first block if the author field is empty;
  222. %            MISC can't be empty---it requires some optional field.
  223. %    3/23/88    (OP)    Version 0.99b for BibTeX 0.99c---changed the three
  224. %            erroneous occurrences of `cite ' to `cite$ '; this
  225. %            change didn't affect the four standard styles, so the
  226. %            0.99a versions of those styles are still current.
  227. %
  228. % The ENTRY declaration
  229. %   Like Scribe's (according to pages 231-2 of the April '84 edition),
  230. %   but no fullauthor or editors fields because BibTeX does name handling.
  231. %   The annote field is commented out here because this family doesn't
  232. %   include an annotated bibliography style.  And in addition to the fields
  233. %   listed here, BibTeX has a built-in crossref field, explained later.
  234. ENTRY
  235. % Fields:
  236.   { address
  237. %        Usually the address of a publisher or other type of organization.
  238. %        Put information in this field only if it helps the reader find the
  239. %        thing---for example you should omit the address of a major
  240. %        publisher entirely.  For a PROCEEDINGS or an INPROCEEDINGS,
  241. %        however, it's the address of the conference; for those two entry
  242. %        types, include the publisher's or organization's address, if
  243. %        necessary, in the publisher or organization field.
  244. %    annote
  245. %        Long annotation---for annotated bibliographies (begins sentence).
  246.     author
  247. %        Name(s) of author(s), in BibTeX name format.
  248.     booktitle
  249. %        Book title when the thing being referenced isn't the whole book.
  250. %        For book entries, the title field should be used instead.
  251.     chapter
  252. %        Chapter (or section or whatever) number.
  253.     edition
  254. %        Edition of a book---should be an ordinal (e.g., "Second").
  255.     editor
  256. %        Name(s) of editor(s), in BibTeX name format.
  257. %        If there is also an author field, then the editor field should be
  258. %        for the book or collection that the work appears in.
  259.     howpublished
  260. %         How something strange has been published (begins sentence).
  261.     institution
  262. %        Sponsoring institution of a technical report.
  263.     journal
  264. %        Journal name (macros are provided for many).
  265.     key
  266. %        Alphabetizing, labeling, and cross-referencing key
  267. %        (needed when an entry has no author or editor).
  268. %    month        not used in apalike
  269. %        Month (macros are provided).
  270.     note
  271. %        To help the reader find a reference (begins sentence).
  272.     number
  273. %        Number of a journal or technical report, or of a work in a series.
  274.     organization
  275. %        Organization sponsoring a conference (or publishing a manual); if
  276. %        the editor (or author) is empty, and if the organization produces
  277. %        an awkward label or cross reference, you should put appropriately
  278. %        condensed organization information in the key field as well.
  279.     pages
  280. %        Page number or numbers (use `--' to separate a range, use `+'
  281. %        to indicate pages following that don't form a simple range).
  282.     publisher
  283. %        Publisher name.
  284.     school
  285. %        School name (for theses).
  286.     series
  287. %        The name of a series or set of books.
  288. %        An individual book will will also have it's own title.
  289.     title
  290. %        The title of the thing you're referred to.
  291.     type
  292. %        Type of a Techreport (e.g., "Research Note") to be used instead of
  293. %        the default "Technical Report"; or, similarly, the type of a
  294. %        thesis; or of a part of a book.
  295.     volume
  296. %        The volume number of a journal or multivolume work.
  297.     year
  298. %        The year should contain only numerals (technically, it should end
  299. %        with four numerals, after purification; doesn't a begin sentence).
  300.   }
  301. % There are no integer entry variables
  302.   {}
  303. % These string entry variables are used to form the citation label.
  304. % In a storage pinch, sort.label can be easily computed on the fly.
  305.   { label extra.label sort.label }
  306. % Each entry function starts by calling output.bibitem, to write the
  307. % \bibitem and its arguments to the .BBL file.  Then the various fields
  308. % are formatted and printed by output or output.check.  Those functions
  309. % handle the writing of separators (commas, periods, \newblock's),
  310. % taking care not to do so when they are passed a null string.
  311. % Finally, fin.entry is called to add the final period and finish the
  312. % entry.
  313. %
  314. % A bibliographic reference is formatted into a number of `blocks':
  315. % in the open format, a block begins on a new line and subsequent
  316. % lines of the block are indented.  A block may contain more than
  317. % one sentence (well, not a grammatical sentence, but something to
  318. % be ended with a sentence ending period).  The entry functions should
  319. % call new.block whenever a block other than the first is about to be
  320. % started.  They should call new.sentence whenever a new sentence is
  321. % to be started.  The output functions will ensure that if two
  322. % new.sentence's occur without any non-null string being output between
  323. % them then there won't be two periods output.  Similarly for two
  324. % successive new.block's.
  325. %
  326. % The output routines don't write their argument immediately.
  327. % Instead, by convention, that argument is saved on the stack to be
  328. % output next time (when we'll know what separator needs to come
  329. % after it).  Meanwhile, the output routine has to pop the pending
  330. % output off the stack, append any needed separator, and write it.
  331. %
  332. % To tell which separator is needed, we maintain an output.state.
  333. % It will be one of these values:
  334. %    before.all        just after the \bibitem
  335. %    mid.sentence        in the middle of a sentence: comma needed
  336. %                    if more sentence is output
  337. %    after.sentence        just after a sentence: period needed
  338. %    after.block        just after a block (and sentence):
  339. %                    period and \newblock needed.
  340. % Note: These styles don't use after.sentence
  341. %
  342. % VAR: output.state : INTEGER        -- state variable for output
  343. %
  344. % The output.nonnull function saves its argument (assumed to be nonnull)
  345. % on the stack, and writes the old saved value followed by any needed
  346. % separator.  The ordering of the tests is decreasing frequency of
  347. % occurrence.
  348. %
  349. % output.nonnull(s) ==
  350. %  BEGIN
  351. %    s := argument on stack
  352. %    if output.state = mid.sentence then
  353. %        write$(pop() * ", ")
  354. %          -- "pop" isn't a function: just use stack top
  355. %    else
  356. %        if output.state = after.block then
  357. %        write$(add.period$(pop()))
  358. %        newline$
  359. %        write$("\newblock ")
  360. %        else
  361. %        if output.state = before.all then
  362. %            write$(pop())
  363. %        else        -- output.state should be after.sentence
  364. %            write$(add.period$(pop()) * " ")
  365. %        fi
  366. %        fi
  367. %        output.state := mid.sentence
  368. %    fi
  369. %    push s on stack
  370. %  END
  371. %
  372. % The output function calls output.nonnull if its argument is non-empty;
  373. % its argument may be a missing field (thus, not necessarily a string)
  374. %
  375. % output(s) ==
  376. %  BEGIN
  377. %    if not empty$(s) then output.nonnull(s)
  378. %    fi
  379. %  END
  380. %
  381. % The output.check function is the same as the output function except that, if
  382. % necessary, output.check warns the user that the t field shouldn't be empty
  383. % (this is because it probably won't be a good reference without the field;
  384. % the entry functions try to make the formatting look reasonable even when
  385. % such fields are empty).
  386. %
  387. % output.check(s,t) ==
  388. %  BEGIN
  389. %    if empty$(s) then
  390. %        warning$("empty " * t * " in " * cite$)
  391. %    else output.nonnull(s)
  392. %    fi
  393. %  END
  394. %
  395. % The output.bibitem function writes the \bibitem for the current entry
  396. % (the label should already have been set up), and sets up the separator
  397. % state for the output functions.  And, it leaves a string on the stack
  398. % as per the output convention.
  399. %
  400. % output.bibitem ==
  401. %  BEGIN
  402. %    newline$
  403. %    write$("\bibitem[")    % for alphabetic labels,
  404. %    write$(label)        % these three lines
  405. %    write$("]{")        % are used
  406. %    write$("\bibitem{")        % this line for numeric labels
  407. %    write$(cite$)
  408. %    write$("}")
  409. %    push "" on stack
  410. %    output.state := before.all
  411. %  END
  412. %
  413. % The fin.entry function finishes off an entry by adding a period to the
  414. % string remaining on the stack.  If the state is still before.all
  415. % then nothing was produced for this entry, so the result will look bad,
  416. % but the user deserves it. (We don't omit the whole entry because the
  417. % entry was cited, and a bibitem is needed to define the citation label.)
  418. %
  419. % fin.entry ==
  420. %  BEGIN
  421. %    write$(add.period$(pop()))
  422. %    newline$
  423. %  END
  424. %
  425. % The new.block function prepares for a new block to be output, and
  426. % new.sentence prepares for a new sentence.
  427. %
  428. % new.block ==
  429. %  BEGIN
  430. %    if output.state <> before.all then
  431. %        output.state := after.block
  432. %    fi
  433. %  END
  434. %
  435. % new.sentence ==
  436. %  BEGIN
  437. %    if output.state <> after.block then
  438. %        if output.state <> before.all then
  439. %        output.state :=  after.sentence
  440. %        fi
  441. %    fi
  442. %  END
  443. %
  444. INTEGERS { output.state before.all mid.sentence after.sentence after.block }
  445. FUNCTION {init.state.consts}
  446. { #0 'before.all :=
  447.   #1 'mid.sentence :=
  448.   #2 'after.sentence :=
  449.   #3 'after.block :=
  450. }
  451. % the variables s and t are temporary string holders
  452. STRINGS { s t }
  453. FUNCTION {output.nonnull}
  454. { 's :=
  455.   output.state mid.sentence =
  456.     { ", " * write$ }
  457.     { output.state after.block =
  458.     { add.period$ write$
  459.       newline$
  460.       "\newblock " write$
  461.     }
  462.     { output.state before.all =
  463.         'write$
  464.         { add.period$ " " * write$ }
  465.       if$
  466.     }
  467.       if$
  468.       mid.sentence 'output.state :=
  469.     }
  470.   if$
  471.   s
  472. }
  473. FUNCTION {output}
  474. { duplicate$ empty$
  475.     'pop$
  476.     'output.nonnull
  477.   if$
  478. }
  479. FUNCTION {output.check}
  480. { 't :=
  481.   duplicate$ empty$
  482.     { pop$ "empty " t * " in " * cite$ * warning$ }
  483.     'output.nonnull
  484.   if$
  485. }
  486. %                    apalike needs this function because
  487. %                    the year has special punctuation;
  488. %                    apalike ignores the month
  489. FUNCTION {output.year.check}
  490. { year empty$
  491.     { "empty year in " cite$ * warning$ }
  492.     { write$
  493.       " (" year * extra.label * ")" *
  494.       mid.sentence 'output.state :=
  495.     }
  496.   if$
  497. }
  498. FUNCTION {output.bibitem}
  499. { newline$
  500.   "\bibitem[" write$
  501.   label write$
  502.   "]{" write$
  503.   cite$ write$
  504.   "}" write$
  505.   newline$
  506.   ""
  507.   before.all 'output.state :=
  508. }
  509. % This function finishes all entries.
  510. FUNCTION {fin.entry}
  511. { add.period$
  512.   write$
  513.   newline$
  514. }
  515. FUNCTION {new.block}
  516. { output.state before.all =
  517.     'skip$
  518.     { after.block 'output.state := }
  519.   if$
  520. }
  521. FUNCTION {new.sentence}
  522. { output.state after.block =
  523.     'skip$
  524.     { output.state before.all =
  525.     'skip$
  526.     { after.sentence 'output.state := }
  527.       if$
  528.     }
  529.   if$
  530. }
  531. % These three functions pop one or two (integer) arguments from the stack
  532. % and push a single one, either 0 or 1.
  533. % The 'skip$ in the `and' and `or' functions are used because
  534. % the corresponding if$ would be idempotent
  535. FUNCTION {not}
  536. {   { #0 }
  537.     { #1 }
  538.   if$
  539. }
  540. FUNCTION {and}
  541. {   'skip$
  542.     { pop$ #0 }
  543.   if$
  544. }
  545. FUNCTION {or}
  546. {   { pop$ #1 }
  547.     'skip$
  548.   if$
  549. }
  550. % Sometimes we begin a new block only if the block will be big enough.  The
  551. % new.block.checka function issues a new.block if its argument is nonempty;
  552. % new.block.checkb does the same if either of its TWO arguments is nonempty.
  553. FUNCTION {new.block.checkb}
  554. { empty$
  555.   swap$ empty$
  556.   and
  557.     'skip$
  558.     'new.block
  559.   if$
  560. }
  561. % Here are some functions for formatting chunks of an entry.
  562. % By convention they either produce a string that can be followed by
  563. % a comma or period (using add.period$, so it is OK to end in a period),
  564. % or they produce the null string.
  565. %
  566. % A useful utility is the field.or.null function, which checks if the
  567. % argument is the result of pushing a `missing' field (one for which no
  568. % assignment was made when the current entry was read in from the database)
  569. % or the result of pushing a string having no non-white-space characters.
  570. % It returns the null string if so, otherwise it returns the field string.
  571. % Its main (but not only) purpose is to guarantee that what's left on the
  572. % stack is a string rather than a missing field.
  573. %
  574. % field.or.null(s) ==
  575. %  BEGIN
  576. %    if empty$(s) then return ""
  577. %    else return s
  578. %  END
  579. %
  580. % Another helper function is emphasize, which returns the argument emphazised,
  581. % if that is non-empty, otherwise it returns the null string.  Italic
  582. % corrections aren't used, so this function should be used when punctation
  583. % will follow the result.
  584. %
  585. % emphasize(s) ==
  586. %  BEGIN
  587. %    if empty$(s) then return ""
  588. %    else return "{\em " * s * "}"
  589. %
  590. % The format.names function formats the argument (which should be in
  591. % BibTeX name format) into "First Von Last, Junior", separated by commas
  592. % and with an "and" before the last (but ending with "et~al." if the last
  593. % of multiple authors is "others").  This function's argument should always
  594. % contain at least one name.
  595. %
  596. % VAR: nameptr, namesleft, numnames: INTEGER
  597. % pseudoVAR: nameresult: STRING        (it's what's accumulated on the stack)
  598. %
  599. % format.names(s) ==
  600. %  BEGIN
  601. %    nameptr := 1
  602. %    numnames := num.names$(s)
  603. %    namesleft := numnames
  604. %    while namesleft > 0
  605. %      do
  606. %                % for full names:
  607. %        t := format.name$(s, nameptr, "{ff~}{vv~}{ll}{, jj}")
  608. %                % for abbreviated first names:
  609. %        t := format.name$(s, nameptr, "{f.~}{vv~}{ll}{, jj}")
  610. %        if nameptr > 1 then
  611. %        if namesleft > 1 then nameresult := nameresult * ", " * t
  612. %        else if numnames > 2
  613. %               then nameresult := nameresult * ","
  614. %             fi
  615. %             if t = "others"
  616. %               then nameresult := nameresult * " et~al."
  617. %               else nameresult := nameresult * " and " * t
  618. %             fi
  619. %        fi
  620. %        else nameresult := t
  621. %        fi
  622. %        nameptr := nameptr + 1
  623. %        namesleft := namesleft - 1
  624. %      od
  625. %    return nameresult
  626. %  END
  627. %
  628. % The format.authors function returns the result of format.names(author)
  629. % if the author is present, or else it returns the null string
  630. %
  631. % format.authors ==
  632. %  BEGIN
  633. %    if empty$(author) then return ""
  634. %    else return format.names(author)
  635. %    fi
  636. %  END
  637. %
  638. % Format.editors is like format.authors, but it uses the editor field,
  639. % and appends ", editor" or ", editors"
  640. %
  641. % format.editors ==
  642. %  BEGIN
  643. %    if empty$(editor) then return ""
  644. %    else
  645. %        if num.names$(editor) > 1 then
  646. %        return format.names(editor) * ", editors"
  647. %        else
  648. %        return format.names(editor) * ", editor"
  649. %        fi
  650. %    fi
  651. %  END
  652. %
  653. % Other formatting functions are similar, so no "comment version" will be
  654. % given for them.
  655. %
  656. % The `pop$' in this function gets rid of the duplicate `empty' value and
  657. % the `skip$' returns the duplicate field value
  658. FUNCTION {field.or.null}
  659. { duplicate$ empty$
  660.     { pop$ "" }
  661.     'skip$
  662.   if$
  663. }
  664. FUNCTION {emphasize}
  665. { duplicate$ empty$
  666.     { pop$ "" }
  667.     { "{\em " swap$ * "}" * }
  668.   if$
  669. }
  670. FUNCTION {caps}
  671. { duplicate$ empty$
  672.     { pop$ "" }
  673.     { "{\sc " swap$ * "}" * }
  674.   if$
  675. }
  676. FUNCTION {embolden}
  677. { duplicate$ empty$
  678.     { pop$ "" }
  679.     { "{\bf " swap$ * "}" * }
  680.   if$
  681. }
  682. INTEGERS { nameptr namesleft numnames }
  683. FUNCTION {format.names}
  684. { 's :=
  685.   #1 'nameptr :=
  686.   s num.names$ 'numnames :=
  687.   numnames 'namesleft :=
  688.     { namesleft #0 > }
  689.     { s nameptr "{vv~}{ll}{, jj}{, f.}" format.name$ 't :=   % last name first
  690.       t "others" =
  691.     'skip$
  692.     { t caps 't := }
  693.       if$
  694.       nameptr #1 >
  695.     { namesleft #1 >
  696.         { ", " * t * }
  697.         { numnames #2 >
  698.         { "," * }
  699.         'skip$
  700.           if$
  701.           t "others" =
  702.         { " {\em et~al.}" * }
  703.         { " and " * t * }
  704.           if$
  705.         }
  706.       if$
  707.     }
  708.     't
  709.       if$
  710.       nameptr #1 + 'nameptr :=
  711.       namesleft #1 - 'namesleft :=
  712.     }
  713.   while$
  714. }
  715. FUNCTION {format.authors}
  716. { author empty$
  717.     { "" }
  718.     { author format.names }
  719.   if$
  720. }
  721. FUNCTION {format.key}            % this function is just for apalike
  722. { empty$
  723.     { key field.or.null }
  724.     { "" }
  725.   if$
  726. }
  727. FUNCTION {format.editors}
  728. { editor empty$
  729.     { "" }
  730.     { editor format.names
  731.       editor num.names$ #1 >
  732.     { ", editors" * }
  733.     { ", editor" * }
  734.       if$
  735.     }
  736.   if$
  737. }
  738. % The format.title function is used for non-book-like titles.
  739. % For most styles we convert to lowercase (except for the very first letter,
  740. % and except for the first one after a colon (followed by whitespace)),
  741. % and hope the user has brace-surrounded words that need to stay capitilized;
  742. % for some styles, however, we leave it as it is in the database.
  743. FUNCTION {format.title}
  744. { title empty$
  745.     { "" }
  746.     'title
  747.   if$
  748. }
  749. % By default, BibTeX sets the global integer variable global.max$ to the BibTeX
  750. % constant glob_str_size, the maximum length of a global string variable.
  751. % Analogously, BibTeX sets the global integer variable entry.max$ to
  752. % ent_str_size, the maximum length of an entry string variable.
  753. % The style designer may change these if necessary (but this is unlikely)
  754. % The n.dashify function makes each single `-' in a string a double `--'
  755. % if it's not already
  756. %
  757. % pseudoVAR: pageresult: STRING        (it's what's accumulated on the stack)
  758. %
  759. % n.dashify(s) ==
  760. %  BEGIN
  761. %    t := s
  762. %    pageresult := ""
  763. %    while (not empty$(t))
  764. %      do
  765. %        if (first character of t = "-")
  766. %          then
  767. %        if (next character isn't)
  768. %          then
  769. %            pageresult := pageresult * "--"
  770. %            t := t with the "-" removed
  771. %          else
  772. %            while (first character of t = "-")
  773. %              do
  774. %            pageresult := pageresult * "-"
  775. %            t := t with the "-" removed
  776. %              od
  777. %        fi
  778. %          else
  779. %        pageresult := pageresult * the first character
  780. %        t := t with the first character removed
  781. %        fi
  782. %      od
  783. %    return pageresult
  784. %  END
  785. FUNCTION {n.dashify}
  786. { 't :=
  787.   ""
  788.     { t empty$ not }
  789.     { t #1 #1 substring$ "-" =
  790.     { t #1 #2 substring$ "--" = not
  791.         { "--" *
  792.           t #2 global.max$ substring$ 't :=
  793.         }
  794.         {   { t #1 #1 substring$ "-" = }
  795.         { "-" *
  796.           t #2 global.max$ substring$ 't :=
  797.         }
  798.           while$
  799.         }
  800.       if$
  801.     }
  802.     { t #1 #1 substring$ *
  803.       t #2 global.max$ substring$ 't :=
  804.     }
  805.       if$
  806.     }
  807.   while$
  808. }
  809. % The format.btitle is for formatting the title field when it is a book-like
  810. % entry---the style used here keeps it in uppers-and-lowers and emphasizes it.
  811. FUNCTION {format.btitle}
  812. { title emphasize
  813. }
  814. % For several functions we'll need to connect two strings with a
  815. % tie (~) if the second one isn't very long (fewer than 3 characters).
  816. % The tie.or.space.connect function does that.  It concatenates the two
  817. % strings on top of the stack, along with either a tie or space between
  818. % them, and puts this concatenation back onto the stack:
  819. %
  820. % tie.or.space.connect(str1,str2) ==
  821. %    BEGIN
  822. %    if text.length$(str2) < 3
  823. %      then return the concatenation of str1, "~", and str2
  824. %      else return the concatenation of str1, " ", and str2
  825. %    END
  826. FUNCTION {tie.or.space.connect}
  827. { duplicate$ text.length$ #3 <
  828.     { "~" }
  829.     { " " }
  830.   if$
  831.   swap$ * *
  832. }
  833. % The either.or.check function complains if both fields or an either-or pair
  834. % are nonempty.
  835. %
  836. % either.or.check(t,s) ==
  837. %  BEGIN
  838. %    if empty$(s) then
  839. %        warning$(can't use both " * t * " fields in " * cite$)
  840. %    fi
  841. %  END
  842. FUNCTION {either.or.check}
  843. { empty$
  844.     'pop$
  845.     { "can't use both " swap$ * " fields in " * cite$ * warning$ }
  846.   if$
  847. }
  848. % The format.bvolume function is for formatting the volume and perhaps
  849. % series name of a multivolume work.  If both a volume and a series field
  850. % are there, we assume the series field is the title of the whole multivolume
  851. % work (the title field should be the title of the thing being referred to),
  852. % and we add an "of <series>".  This function is called in mid-sentence.
  853. FUNCTION {format.bvolume}
  854. { volume empty$
  855.     { "" }
  856.     { "volume" volume tie.or.space.connect
  857.       series empty$
  858.     'skip$
  859.     { " of " * series emphasize * }
  860.       if$
  861.       "volume and number" number either.or.check
  862.     }
  863.   if$
  864. }
  865. % The format.number.series function is for formatting the series name
  866. % and perhaps number of a work in a series.  This function is similar to
  867. % format.bvolume, although for this one the series must exist (and the
  868. % volume must not exist).  If the number field is empty we output either
  869. % the series field unchanged if it exists or else the null string.
  870. % If both the number and series fields are there we assume the series field
  871. % gives the name of the whole series (the title field should be the title
  872. % of the work being one referred to), and we add an "in <series>".
  873. % We capitilize Number when this function is used at the beginning of a block.
  874. FUNCTION {format.number.series}
  875. { volume empty$
  876.     { number empty$
  877.     { series field.or.null }
  878.     { output.state mid.sentence =
  879.         { "number" }
  880.         { "Number" }
  881.       if$
  882.       number tie.or.space.connect
  883.       series empty$
  884.         { "there's a number but no series in " cite$ * warning$ }
  885.         { " in " * series * }
  886.       if$
  887.     }
  888.       if$
  889.     }
  890.     { "" }
  891.   if$
  892. }
  893. % The format.edition function appends " edition" to the edition, if present.
  894. % We lowercase the edition (it should be something like "Third"), because
  895. % this doesn't start a sentence.
  896. FUNCTION {format.edition}
  897. { edition empty$
  898.     { "" }
  899.     { output.state mid.sentence =
  900.     { edition "l" change.case$ " edition" * }
  901.     { edition "t" change.case$ " edition" * }
  902.       if$
  903.     }
  904.   if$
  905. }
  906. % The format.pages function is used for formatting a page range in a book
  907. % (and in rare circumstances, an article).
  908. %
  909. % The multi.page.check function examines the page field for a "-" or "," or "+"
  910. % so that format.pages can use "page" instead of "pages" if none exists.
  911. % Note: global.max$ here means "take the rest of the string"
  912. %
  913. % VAR: multiresult: INTEGER    (actually, a boolean)
  914. %
  915. % multi.page.check(s) ==
  916. %  BEGIN
  917. %    t := s
  918. %    multiresult := false
  919. %    while ((not multiresult) and (not empty$(t)))
  920. %      do
  921. %        if (first character of t = "-" or "," or "+")
  922. %          then multiresult := true
  923. %          else t := t with the first character removed
  924. %        fi
  925. %      od
  926. %    return multiresult
  927. %  END
  928. INTEGERS { multiresult }
  929. FUNCTION {multi.page.check}
  930. { 't :=
  931.   #0 'multiresult :=
  932.     { multiresult not
  933.       t empty$ not
  934.       and
  935.     }
  936.     { t #1 #1 substring$
  937.       duplicate$ "-" =
  938.       swap$ duplicate$ "," =
  939.       swap$ "+" =
  940.       or or
  941.     { #1 'multiresult := }
  942.     { t #2 global.max$ substring$ 't := }
  943.       if$
  944.     }
  945.   while$
  946.   multiresult
  947. }
  948. % This function doesn't begin a sentence so "pages" isn't capitalized.
  949. % Other functions that use this should keep that in mind.
  950. FUNCTION {format.pages}
  951. { pages empty$
  952.     { "" }
  953.     { pages multi.page.check
  954.     { "pages" pages n.dashify tie.or.space.connect }
  955.     { "page" pages tie.or.space.connect }
  956.       if$
  957.     }
  958.   if$
  959. }
  960. % The format.vol.num.pages function is for the volume, number, and page range
  961. % of a journal article.  We use the format:  vol(number):pages, with some
  962. % variations for empty fields.  This doesn't begin a sentence.
  963. FUNCTION {format.vol.num.pages}
  964. { volume field.or.null embolden
  965.   " " swap$ * *
  966.   pages empty$
  967.     'skip$
  968.     { duplicate$ empty$
  969.     { pop$ format.pages }
  970.     { ", " * pages n.dashify * }
  971.       if$
  972.     }
  973.   if$
  974. }
  975. % The format.chapter.pages, if the chapter is present, puts whatever is in the
  976. % type field (or else "chapter" if type is empty) in front of a chapter number.
  977. % It then appends the pages, if present.  This doesn't begin a sentence.
  978. FUNCTION {format.chapter.pages}
  979. { chapter empty$
  980.     'format.pages
  981.     { type empty$
  982.     { "chapter" }
  983.     { type "l" change.case$ }
  984.       if$
  985.       chapter tie.or.space.connect
  986.       pages empty$
  987.     'skip$
  988.     { ", " * format.pages * }
  989.       if$
  990.     }
  991.   if$
  992. }
  993. % The format.in.ed.booktitle function is used for starting out a sentence
  994. % that begins "In <booktitle>", putting an editor before the title if one
  995. % exists.
  996. FUNCTION {format.in.ed.booktitle}
  997. { booktitle empty$
  998.     { "" }
  999.     { editor empty$
  1000.     { "In " booktitle emphasize * }
  1001.     { "In " format.editors * ", " * booktitle emphasize * }
  1002.       if$
  1003.     }
  1004.   if$
  1005. }
  1006. % The function format.thesis.type returns either the (case-changed) type field,
  1007. % if it is defined, or else the default string already on the stack
  1008. % (like "Master's thesis" or "PhD thesis").
  1009. FUNCTION {format.thesis.type}
  1010. { type empty$
  1011.     'skip$
  1012.     { pop$
  1013.       type "t" change.case$
  1014.     }
  1015.   if$
  1016. }
  1017. % The function format.tr.number makes a string starting with "Technical Report"
  1018. % (or type, if that field is defined), followed by the number if there is one;
  1019. % it returns the starting part (with a case change) even if there is no number.
  1020. % This is used at the beginning of a sentence.
  1021. FUNCTION {format.tr.number}
  1022. { type empty$
  1023.     { "Technical Report" }
  1024.     'type
  1025.   if$
  1026.   number empty$
  1027.     { "t" change.case$ }
  1028.     { number tie.or.space.connect }
  1029.   if$
  1030. }
  1031. % Now come the cross-referencing functions (these are invoked because
  1032. % one entry in the database file(s) cross-references another, by giving
  1033. % the other entry's database key in a `crossref' field).  This feature
  1034. % allows one or more titled things that are part of a larger titled
  1035. % thing to cross-reference the larger thing.  These styles allow for
  1036. % five posibilities: (1) an ARTICLE may cross-reference an ARTICLE;
  1037. % (2) a BOOK, (3) INBOOK, or (4) INCOLLECTION may cross-reference a BOOK;
  1038. % or (5) an INPROCEEDINGS may cross-reference a PROCEEDINGS.
  1039. % Each of these is explained in more detail later.
  1040. %
  1041. % An ARTICLE entry type may cross reference another ARTICLE (this is
  1042. % intended for when an entire journal is devoted to a single topic---
  1043. % but since there is no JOURNAL entry type, the journal, too, should be
  1044. % classified as an ARTICLE but without the author and title fields).
  1045. % This will result in two warning messages for the journal's entry
  1046. % if it's included in the reference list, but such is life.
  1047. %
  1048. % format.article.crossref ==
  1049. %  BEGIN
  1050. %    if empty$(key) then
  1051. %        if empty$(journal) then
  1052. %        warning$("need key or journal for " * cite$ *
  1053. %                        " to crossref " * crossref)
  1054. %        return(" \cite{" * crossref * "}")
  1055. %        else
  1056. %        return("In " * emphazise.correct (journal) *
  1057. %                        " \cite{" * crossref * "}")
  1058. %        fi
  1059. %    else
  1060. %        return("In " * key * " \cite{" * crossref * "}")
  1061. %    fi
  1062. %  END
  1063. %
  1064. % The other cross-referencing functions are similar, so no "comment version"
  1065. % will be given for them.
  1066. FUNCTION {format.article.crossref}
  1067. { "In"                            % this is for apalike
  1068.   " \cite{" * crossref * "}" *
  1069. }
  1070. % A BOOK (or INBOOK) entry type (assumed to be for a single volume in a
  1071. % multivolume work) may cross reference another BOOK (the entire multivolume).
  1072. % Usually there will be an editor, in which case we use that to construct the
  1073. % cross reference; otherwise we use a nonempty key field or else the series
  1074. % field (since the series gives the title of the multivolume work).
  1075. FUNCTION {format.book.crossref}
  1076. { volume empty$
  1077.     { "empty volume in " cite$ * "'s crossref of " * crossref * warning$
  1078.       "In "
  1079.     }
  1080.     { "Volume" volume tie.or.space.connect
  1081.       " of " *
  1082.     }
  1083.   if$
  1084.   "\cite{" * crossref * "}" *                % this is for apalike
  1085. }
  1086. % An INCOLLECTION entry type may cross reference a BOOK (assumed to be the
  1087. % collection), or an INPROCEEDINGS may cross reference a PROCEEDINGS.
  1088. % Often there will be an editor, in which case we use that to construct
  1089. % the cross reference; otherwise we use a nonempty key field or else
  1090. % the booktitle field (which gives the cross-referenced work's title).
  1091. FUNCTION {format.incoll.inproc.crossref}
  1092. { "In"                            % this is for apalike
  1093.   " \cite{" * crossref * "}" *
  1094. }
  1095. % Now we define the type functions for all entry types that may appear
  1096. % in the .BIB file---e.g., functions like `article' and `book'.  These
  1097. % are the routines that actually generate the .BBL-file output for
  1098. % the entry.  These must all precede the READ command.  In addition, the
  1099. % style designer should have a function `default.type' for unknown types.
  1100. % Note: The fields (within each list) are listed in order of appearance,
  1101. % except as described for an `inbook' or a `proceedings'.
  1102. %
  1103. % The article function is for an article in a journal.  An article may
  1104. % CROSSREF another article.
  1105. %    Required fields: author, title, journal, year
  1106. %    Optional fields: volume, number, pages, month, note
  1107. %
  1108. % article ==
  1109. %  BEGIN
  1110. %    output.bibitem
  1111. %    output.check(format.authors,"author")
  1112. %    new.block
  1113. %    output.check(format.title,"title")
  1114. %    new.block
  1115. %    if missing$(crossref) then
  1116. %        output.check(emphasize(journal),"journal")
  1117. %        output(format.vol.num.pages)
  1118. %        output.check(format.date,"year")
  1119. %       else
  1120. %        output.nonnull(format.article.crossref)
  1121. %        output(format.pages)
  1122. %    fi
  1123. %    new.block
  1124. %    output(note)
  1125. %    fin.entry
  1126. %  END
  1127. %
  1128. % The book function is for a whole book.  A book may CROSSREF another book.
  1129. %    Required fields: author or editor, title, publisher, year
  1130. %    Optional fields: volume or number, series, address, edition, month,
  1131. %            note
  1132. %
  1133. % book ==
  1134. %  BEGIN
  1135. %    if empty$(author) then output.check(format.editors,"author and editor")
  1136. %    else    output.check(format.authors,"author")
  1137. %        if missing$(crossref) then
  1138. %            either.or.check("author and editor",editor)
  1139. %        fi
  1140. %    fi
  1141. %    new.block
  1142. %    output.check(format.btitle,"title")
  1143. %    if missing$(crossref) then
  1144. %        output(format.bvolume)
  1145. %        new.block
  1146. %        output(format.number.series)
  1147. %        new.sentence
  1148. %        output.check(publisher,"publisher")
  1149. %        output(address)
  1150. %       else
  1151. %        new.block
  1152. %        output.nonnull(format.book.crossref)
  1153. %    fi
  1154. %    output(format.edition)
  1155. %    output.check(format.date,"year")
  1156. %    new.block
  1157. %    output(note)
  1158. %    fin.entry
  1159. %  END
  1160. %
  1161. % The other entry functions are all quite similar, so no "comment version"
  1162. % will be given for them.
  1163. FUNCTION {article}
  1164. { output.bibitem
  1165.   format.authors "author" output.check
  1166.   author format.key output                % special for
  1167.   output.year.check                    % apalike
  1168.   new.block
  1169.   crossref missing$
  1170.     { journal emphasize
  1171.       format.vol.num.pages output
  1172.     }
  1173.     { format.article.crossref output.nonnull
  1174.       format.pages output
  1175.     }
  1176.   if$
  1177.   new.block
  1178.   note output
  1179.   fin.entry
  1180. }
  1181. FUNCTION {book}
  1182. { output.bibitem
  1183.   author empty$
  1184.     { format.editors "author and editor" output.check
  1185.       editor format.key output
  1186.     }
  1187.     { format.authors output.nonnull
  1188.       crossref missing$
  1189.     { "author and editor" editor either.or.check }
  1190.     'skip$
  1191.       if$
  1192.     }
  1193.   if$
  1194.   output.year.check                % special for apalike
  1195.   new.block
  1196.   format.btitle "title" output.check
  1197.   crossref missing$
  1198.     { format.bvolume output
  1199.       new.block
  1200.       format.number.series output
  1201.       new.sentence
  1202.       publisher "publisher" output.check
  1203.       address output
  1204.     }
  1205.     { new.block
  1206.       format.book.crossref output.nonnull
  1207.     }
  1208.   if$
  1209.   format.edition output
  1210.   new.block
  1211.   note output
  1212.   fin.entry
  1213. }
  1214. % A booklet is a bound thing without a publisher or sponsoring institution.
  1215. %    Required: title
  1216. %    Optional: author, howpublished, address, month, year, note
  1217. FUNCTION {booklet}
  1218. { output.bibitem
  1219.   format.authors output
  1220.   author format.key output                % special for
  1221.   output.year.check                    % apalike
  1222.   new.block
  1223.   format.title "title" output.check
  1224.   new.block
  1225.   howpublished output
  1226.   address output
  1227.   new.block
  1228.   note output
  1229.   fin.entry
  1230. }
  1231. % For the conference entry type, see inproceedings.
  1232. % An inbook is a piece of a book: either a chapter and/or a page range.
  1233. % It may CROSSREF a book.  If there's no volume field, the type field
  1234. % will come before number and series.
  1235. %    Required: author or editor, title, chapter and/or pages, publisher,year
  1236. %    Optional: volume or number, series, type, address, edition, month, note
  1237. FUNCTION {inbook}
  1238. { output.bibitem
  1239.   author empty$
  1240.     { format.editors "author and editor" output.check
  1241.       editor format.key output
  1242.     }
  1243.     { format.authors output.nonnull
  1244.       crossref missing$
  1245.     { "author and editor" editor either.or.check }
  1246.     'skip$
  1247.       if$
  1248.     }
  1249.   if$
  1250.   output.year.check                % special for apalike
  1251.   new.block
  1252.   format.btitle "title" output.check
  1253.   crossref missing$
  1254.     { format.bvolume output
  1255.       format.chapter.pages "chapter and pages" output.check
  1256.       new.block
  1257.       format.number.series output
  1258.       new.sentence
  1259.       publisher "publisher" output.check
  1260.       address output
  1261.     }
  1262.     { format.chapter.pages "chapter and pages" output.check
  1263.       new.block
  1264.       format.book.crossref output.nonnull
  1265.     }
  1266.   if$
  1267.   format.edition output
  1268.   new.block
  1269.   note output
  1270.   fin.entry
  1271. }
  1272. % An incollection is like inbook, but where there is a separate title
  1273. % for the referenced thing (and perhaps an editor for the whole).
  1274. % An incollection may CROSSREF a book.
  1275. %    Required: author, title, booktitle, publisher, year
  1276. %    Optional: editor, volume or number, series, type, chapter, pages,
  1277. %            address, edition, month, note
  1278. FUNCTION {incollection}
  1279. { output.bibitem
  1280.   format.authors "author" output.check
  1281.   author format.key output                % special for
  1282.   output.year.check                    % apalike
  1283.   new.block
  1284.   format.title "title" output.check
  1285.   new.block
  1286.   crossref missing$
  1287.     { format.in.ed.booktitle "booktitle" output.check
  1288.       format.bvolume output
  1289.       format.number.series output
  1290.       format.chapter.pages output
  1291.       new.sentence
  1292.       publisher "publisher" output.check
  1293.       address output
  1294.       format.edition output
  1295.     }
  1296.     { format.incoll.inproc.crossref output.nonnull
  1297.       format.chapter.pages output
  1298.     }
  1299.   if$
  1300.   new.block
  1301.   note output
  1302.   fin.entry
  1303. }
  1304. % An inproceedings is an article in a conference proceedings, and it may
  1305. % CROSSREF a proceedings.  If there's no address field, the month (& year)
  1306. % will appear just before note.
  1307. %    Required: author, title, booktitle, year
  1308. %    Optional: editor, volume or number, series, pages, address, month,
  1309. %            organization, publisher, note
  1310. FUNCTION {inproceedings}
  1311. { output.bibitem
  1312.   format.authors "author" output.check
  1313.   author format.key output                % special for
  1314.   output.year.check                    % apalike
  1315.   new.block
  1316.   format.title "title" output.check
  1317.   new.block
  1318.   crossref missing$
  1319.     { format.in.ed.booktitle "booktitle" output.check
  1320.       format.bvolume output
  1321.       format.number.series output
  1322.       format.pages output
  1323.       address output                    % for apalike
  1324.       new.sentence                    % there's no year
  1325.       organization output                % here so things
  1326.       publisher output                    % are simpler
  1327.     }
  1328.     { format.incoll.inproc.crossref output.nonnull
  1329.       format.pages output
  1330.     }
  1331.   if$
  1332.   new.block
  1333.   note output
  1334.   fin.entry
  1335. }
  1336. % The conference function is included for Scribe compatibility.
  1337. FUNCTION {conference} { inproceedings }
  1338. % A manual is technical documentation.
  1339. %    Required: title
  1340. %    Optional: author, organization, address, edition, month, year, note
  1341. FUNCTION {manual}
  1342. { output.bibitem
  1343.   format.authors output
  1344.   author format.key output                % special for
  1345.   output.year.check                    % apalike
  1346.   new.block
  1347.   format.btitle "title" output.check
  1348.   organization address new.block.checkb
  1349.   organization output
  1350.   address output
  1351.   format.edition output
  1352.   new.block
  1353.   note output
  1354.   fin.entry
  1355. }
  1356. % A mastersthesis is a Master's thesis.
  1357. %    Required: author, title, school, year
  1358. %    Optional: type, address, month, note
  1359. FUNCTION {mastersthesis}
  1360. { output.bibitem
  1361.   format.authors "author" output.check
  1362.   author format.key output                % special for
  1363.   output.year.check                    % apalike
  1364.   new.block
  1365.   format.title "title" output.check
  1366.   new.block
  1367.   "Master's thesis" format.thesis.type output.nonnull
  1368.   school "school" output.check
  1369.   address output
  1370.   new.block
  1371.   note output
  1372.   fin.entry
  1373. }
  1374. % A misc is something that doesn't fit elsewhere.
  1375. %    Required: at least one of the `optional' fields
  1376. %    Optional: author, title, howpublished, month, year, note
  1377. FUNCTION {misc}
  1378. { output.bibitem
  1379.   format.authors output
  1380.   author format.key output                % special for
  1381.   output.year.check                    % apalike
  1382.   new.block
  1383.   format.title output
  1384.   new.block
  1385.   howpublished output
  1386.   new.block
  1387.   note output
  1388.   fin.entry
  1389. }
  1390. % A phdthesis is like a mastersthesis.
  1391. %    Required: author, title, school, year
  1392. %    Optional: type, address, month, note
  1393. FUNCTION {phdthesis}
  1394. { output.bibitem
  1395.   format.authors "author" output.check
  1396.   author format.key output                % special for
  1397.   output.year.check                    % apalike
  1398.   new.block
  1399.   format.btitle "title" output.check
  1400.   new.block
  1401.   "PhD thesis" format.thesis.type output.nonnull
  1402.   school "school" output.check
  1403.   address output
  1404.   new.block
  1405.   note output
  1406.   fin.entry
  1407. }
  1408. % A proceedings is a conference proceedings.
  1409. % If there is an organization but no editor field, the organization will
  1410. % appear as the first optional field (we try to make the first block nonempty);
  1411. % if there's no address field, the month (& year) will appear just before note.
  1412. %    Required: title, year
  1413. %    Optional: editor, volume or number, series, address, month,
  1414. %            organization, publisher, note
  1415. FUNCTION {proceedings}
  1416. { output.bibitem
  1417.   format.editors output
  1418.   editor format.key output                % special for
  1419.   output.year.check                    % apalike
  1420.   new.block
  1421.   format.btitle "title" output.check
  1422.   format.bvolume output
  1423.   format.number.series output
  1424.   address output                % for apalike
  1425.   new.sentence                    % we always output
  1426.   organization output                % a nonempty organization
  1427.   publisher output                % here
  1428.   new.block
  1429.   note output
  1430.   fin.entry
  1431. }
  1432. % A techreport is a technical report.
  1433. %    Required: author, title, institution, year
  1434. %    Optional: type, number, address, month, note
  1435. FUNCTION {techreport}
  1436. { output.bibitem
  1437.   format.authors "author" output.check
  1438.   author format.key output                % special for
  1439.   output.year.check                    % apalike
  1440.   new.block
  1441.   format.title "title" output.check
  1442.   new.block
  1443.   format.tr.number output.nonnull
  1444.   institution "institution" output.check
  1445.   address output
  1446.   new.block
  1447.   note output
  1448.   fin.entry
  1449. }
  1450. % An unpublished is something that hasn't been published.
  1451. %    Required: author, title, note
  1452. %    Optional: month, year
  1453. FUNCTION {unpublished}
  1454. { output.bibitem
  1455.   format.authors "author" output.check
  1456.   author format.key output                % special for
  1457.   output.year.check                    % apalike
  1458.   new.block
  1459.   format.title "title" output.check
  1460.   new.block
  1461.   note "note" output.check
  1462.   fin.entry
  1463. }
  1464. % We use entry type `misc' for an unknown type; BibTeX gives a warning.
  1465. FUNCTION {default.type} { misc }
  1466. % Here are macros for common things that may vary from style to style.
  1467. % Users are encouraged to use these macros.
  1468. %
  1469. % Months are either written out in full or abbreviated
  1470. MACRO {jan} {"January"}
  1471. MACRO {feb} {"February"}
  1472. MACRO {mar} {"March"}
  1473. MACRO {apr} {"April"}
  1474. MACRO {may} {"May"}
  1475. MACRO {jun} {"June"}
  1476. MACRO {jul} {"July"}
  1477. MACRO {aug} {"August"}
  1478. MACRO {sep} {"September"}
  1479. MACRO {oct} {"October"}
  1480. MACRO {nov} {"November"}
  1481. MACRO {dec} {"December"}
  1482. % Journals are either written out in full or abbreviated;
  1483. % the abbreviations are like those found in ACM publications.
  1484. %
  1485. % To get a completely different set of abbreviations, it may be best to make
  1486. % a separate .bib file with nothing but those abbreviations; users could then
  1487. % include that file name as the first argument to the \bibliography command
  1488. MACRO {acmcs} {"ACM Comput. Surv."}
  1489. MACRO {acta} {"Acta Inf."}
  1490. MACRO {cacm} {"Commun. ACM"}
  1491. MACRO {ibmjrd} {"IBM J. Res. Dev."}
  1492. MACRO {ibmsj} {"IBM Syst.~J."}
  1493. MACRO {ieeese} {"IEEE Trans. Softw. Eng."}
  1494. MACRO {ieeetc} {"IEEE Trans. Comput."}
  1495. MACRO {ieeetcad}
  1496.  {"IEEE Trans. Comput.-Aided Design Integrated Circuits"}
  1497. MACRO {ipl} {"Inf. Process. Lett."}
  1498. MACRO {jacm} {"J.~ACM"}
  1499. MACRO {jcss} {"J.~Comput. Syst. Sci."}
  1500. MACRO {scp} {"Sci. Comput. Programming"}
  1501. MACRO {sicomp} {"SIAM J. Comput."}
  1502. MACRO {tocs} {"ACM Trans. Comput. Syst."}
  1503. MACRO {tods} {"ACM Trans. Database Syst."}
  1504. MACRO {tog} {"ACM Trans. Gr."}
  1505. MACRO {toms} {"ACM Trans. Math. Softw."}
  1506. MACRO {toois} {"ACM Trans. Office Inf. Syst."}
  1507. MACRO {toplas} {"ACM Trans. Prog. Lang. Syst."}
  1508. MACRO {tcs} {"Theoretical Comput. Sci."}
  1509. %% /usr/local/lib/tex/bibtex/phyjfull.btx, Tue Jun 30 08:37:48 1992
  1510. %% Edit by Nelson H. F. Beebe <beebe@alfred.math.utah.edu>
  1511. %% Change file names in leading comment
  1512. % Journal Title Abbreviations from the Physical Review Style and Notation
  1513. %    Guide, July, 1983, in BAPS Vol. 28.
  1514. %  Selected by Cris Barnes and Charles Karney, March 1988
  1515. % IMPORTANT!! Don't make changes to this file without making the
  1516. %           corresponding changes to
  1517. %            phyjabb.bib
  1518. %            phyjabb.btx
  1519. MACRO {advp} {"Advances in Physics"}
  1520. MACRO {ajp} {"American Journal of Physics"}
  1521. MACRO {ao} {"Applied Optics"}
  1522. MACRO {apl} {"Applied Physics Letters"}
  1523. MACRO {apj} {"Astrophysical Journal"}
  1524. MACRO {baps} {"Bulletin of the American Physical Society"}
  1525. MACRO {cpc} {"Computer Physics Communications"}
  1526. MACRO {cppcf} {"Comments on Plasma Physics and Controlled Fusion"}
  1527. MACRO {fed} {"Fusion Engineering and Design"}
  1528. MACRO {ft} {"Fusion Technology"}
  1529. MACRO {ieeens} {"IEEE Transactions on Nuclear Science"}
  1530. MACRO {ieeeps} {"IEEE Transactions on Plasma Science"}
  1531. MACRO {ijimw} {"International Journal of Infrared and Millimeter Waves"}
  1532. MACRO {ip} {"Infrared Physics"}
  1533. MACRO {jap} {"Journal of Applied Physics"}
  1534. MACRO {jcp} {"Journal of Computational Physics"}
  1535. MACRO {jetp} {"Soviet Physics-JETP"}
  1536. MACRO {jfe} {"Journal of Fusion Energy"}
  1537. MACRO {jfm} {"Journal of Fluid Mechanics"}
  1538. MACRO {jgr} {"Journal of Geophysical Research"}
  1539. MACRO {jmp} {"Journal of Mathematical Physics"}
  1540. MACRO {jne} {"Journal of Nuclear Energy"}
  1541. MACRO {jnec} {"Journal of Nuclear Energy, Part C: Plasma Physics, Accelerators, Thermonuclear Research"}
  1542. MACRO {jnm} {"Journal of Nuclear Materials"}
  1543. MACRO {josa} {"Journal of the Optical Society of America"}
  1544. MACRO {jpp} {"Journal of Plasma Physics"}
  1545. MACRO {jpsj} {"Journal of the Physical Society of Japan"}
  1546. MACRO {jvst} {"Journal of Vacuum Science and Technology"}
  1547. MACRO {nedf} {"Nuclear Engineering and Design/Fusion"}
  1548. MACRO {nf} {"Nuclear Fusion"}
  1549. MACRO {nim} {"Nuclear Instruments and Methods"}
  1550. MACRO {nimpr} {"Nuclear Instruments and Methods in Physics Research"}
  1551. MACRO {nt/f} {"Nuclear Technology/Fusion"}
  1552. MACRO {pf} {"Physics of Fluids"}
  1553. MACRO {pfa} {"Physics of Fluids A: Fluid Dynamics"}
  1554. MACRO {pfb} {"Physics of Fluids B: Plasma Physics"}
  1555. MACRO {pl} {"Physics Letters"}
  1556. MACRO {pla} {"Physics Letters A"}
  1557. MACRO {pnas} {"Proceedings of the National Academy of Sciences of the USA"}
  1558. MACRO {pp} {"Plasma Physics"}
  1559. MACRO {ppcf} {"Plasma Physics and Controlled Fusion"}
  1560. MACRO {prl} {"Physical Review Letters"}
  1561. MACRO {pr} {"Physical Review"}
  1562. MACRO {pra} {"Physical Review A: General Physics"}
  1563. MACRO {ps} {"Physica Scripta"}
  1564. MACRO {rmp} {"Reviews of Modern Physics"}
  1565. MACRO {rsi} {"Review of Scientific Instruments"}
  1566. MACRO {sjpp} {"Soviet Journal of Plasma Phys."}
  1567. MACRO {spd} {"Soviet Physics-Doklady"}
  1568. MACRO {sptp} {"Soviet Physics-Technical Physics"}
  1569. MACRO {spu} {"Soviet Physics-Uspeki"}
  1570. % Now we read in the .BIB entries.
  1571. READ
  1572. % The sortify function converts to lower case after purify$ing; it's
  1573. % used in sorting and in computing alphabetic labels after sorting
  1574. %
  1575. % The chop.word(w,len,s) function returns either s or, if the first len
  1576. % letters of s equals w (this comparison is done in the third line of the
  1577. % function's definition), it returns that part of s after w.
  1578. FUNCTION {sortify}
  1579. { purify$
  1580.   "l" change.case$
  1581. }
  1582. INTEGERS { len }
  1583. FUNCTION {chop.word}
  1584. { 's :=
  1585.   'len :=
  1586.   s #1 len substring$ =
  1587.     { s len #1 + global.max$ substring$ }
  1588.     's
  1589.   if$
  1590. }
  1591. % This long comment applies only to alphabetic labels
  1592. %
  1593. % The format.lab.names function makes a short label by using the initials of
  1594. % the von and Last parts of the names (but if there are more than four names,
  1595. % (i.e., people) it truncates after three and adds a superscripted "+";
  1596. % it also adds such a "+" if the last of multiple authors is "others").
  1597. % If there is only one name, and its von and Last parts combined have just
  1598. % a single name-token ("Knuth" has a single token, "Brinch Hansen" has two),
  1599. % we take the first three letters of the last name.  The boolean
  1600. % et.al.char.used tells whether we've used a superscripted "+", so that we
  1601. % know whether to include a LaTeX macro for it.
  1602. %
  1603. % format.lab.names(s) ==
  1604. %  BEGIN
  1605. %    numnames := num.names$(s)
  1606. %    if numnames > 1 then
  1607. %        if numnames > 4 then
  1608. %        namesleft := 3
  1609. %        else
  1610. %        namesleft := numnames
  1611. %        nameptr := 1
  1612. %        nameresult := ""
  1613. %        while namesleft > 0
  1614. %          do
  1615. %        if (name_ptr = numnames) and
  1616. %             format.name$(s, nameptr, "{ff }{vv }{ll}{ jj}") = "others"
  1617. %           then nameresult := nameresult * "{\etalchar{+}}"
  1618. %            et.al.char.used := true
  1619. %           else nameresult := nameresult *
  1620. %                format.name$(s, nameptr, "{v{}}{l{}}")
  1621. %        nameptr := nameptr + 1
  1622. %        namesleft := namesleft - 1
  1623. %          od
  1624. %        if numnames > 4 then
  1625. %        nameresult := nameresult * "{\etalchar{+}}"
  1626. %        et.al.char.used := true
  1627. %    else
  1628. %        t := format.name$(s, 1, "{v{}}{l{}}")
  1629. %        if text.length$(t) < 2 then    % there's just one name-token
  1630. %        nameresult := text.prefix$(format.name$(s,1,"{ll}"),3)
  1631. %        else
  1632. %        nameresult := t
  1633. %        fi
  1634. %    fi
  1635. %    return nameresult
  1636. %  END
  1637. %
  1638. % Exactly what fields we look at in constructing the primary part of the label
  1639. % depends on the entry type; this selectivity (as opposed to, say, always
  1640. % looking at author, then editor, then key) helps ensure that "ignored" fields,
  1641. % as described in the LaTeX book, really are ignored.  Note that MISC is part
  1642. % of the deepest `else' clause in the nested part of calc.label; thus, any
  1643. % unrecognized entry type in the database is handled correctly.
  1644. %
  1645. % There is one auxiliary function for each of the four different sequences of
  1646. % fields we use.  The first of these functions looks at the author field, and
  1647. % then, if necessary, the key field.  The other three functions, which might
  1648. % look at two fields and the key field, are similar, except that the key field
  1649. % takes precedence over the organization field (for labels---not for sorting).
  1650. %
  1651. % The calc.label function calculates the preliminary label of an entry, which
  1652. % is formed by taking three letters of information from the author or editor or
  1653. % key or organization field (depending on the entry type and on what's empty,
  1654. % but ignoring a leading "The " in the organization), and appending the last
  1655. % two characters (digits) of the year. It is an error if the appropriate fields
  1656. % among author, editor, organization, and key are missing, and we use
  1657. % the first three letters of the cite$ in desperation when this happens.
  1658. % The resulting label has the year part, but not the name part, purify$ed
  1659. % (purify$ing the year allows some sorting shenanigans by the user).
  1660. %
  1661. % This function also calculates the version of the label to be used in sorting.
  1662. %
  1663. % The final label may need a trailing 'a', 'b', etc., to distinguish it from
  1664. % otherwise identical labels, but we can't calculated those "extra.label"s
  1665. % until after sorting.
  1666. %
  1667. % calc.label ==
  1668. %  BEGIN
  1669. %    if type$ = "book" or "inbook" then
  1670. %        author.editor.key.label
  1671. %    else if type$ = "proceedings" then
  1672. %        editor.key.organization.label
  1673. %    else if type$ = "manual" then
  1674. %        author.key.organization.label
  1675. %    else
  1676. %        author.key.label
  1677. %    fi fi fi
  1678. %    label := label * substring$(purify$(field.or.null(year)), -1, 2)
  1679. %        % assuming we will also sort, we calculate a sort.label
  1680. %    sort.label := sortify(label), but use the last four, not two, digits
  1681. %  END
  1682. %            There are three apalike cases: one person (Jones),
  1683. %            two (Jones and de~Bruijn), and more (Jones et~al.).
  1684. %            This function is much like format.crossref.editors.
  1685. %
  1686. FUNCTION {format.lab.names}
  1687. { 's :=
  1688.   s #1 "{vv~}{ll}" format.name$ caps
  1689.   s num.names$ duplicate$
  1690.   #2 >
  1691.     { pop$ " {\em et~al.}" * }
  1692.     { #2 <
  1693.     'skip$
  1694.     { s #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
  1695.         { " {\em et~al.}" * }
  1696.         { " and " * s #2 "{vv~}{ll}" format.name$ caps * }
  1697.       if$
  1698.     }
  1699.       if$
  1700.     }
  1701.   if$
  1702. }
  1703. FUNCTION {author.key.label}
  1704. { author empty$
  1705.     { key empty$
  1706.     { cite$ #1 #3 substring$ }
  1707.     'key                    % apalike uses the whole key
  1708.       if$
  1709.     }
  1710.     { author format.lab.names }
  1711.   if$
  1712. }
  1713. FUNCTION {author.editor.key.label}
  1714. { author empty$
  1715.     { editor empty$
  1716.     { key empty$
  1717.         { cite$ #1 #3 substring$ }
  1718.         'key                % apalike uses the whole key
  1719.       if$
  1720.     }
  1721.     { editor format.lab.names }
  1722.       if$
  1723.     }
  1724.     { author format.lab.names }
  1725.   if$
  1726. }
  1727. FUNCTION {editor.key.label}
  1728. { editor empty$
  1729.     { key empty$
  1730.     { cite$ #1 #3 substring$ }
  1731.     'key            % apalike uses the whole key, no organization
  1732.       if$
  1733.     }
  1734.     { editor format.lab.names }
  1735.   if$
  1736. }
  1737. FUNCTION {calc.label}
  1738. { type$ "book" =
  1739.   type$ "inbook" =
  1740.   or
  1741.     'author.editor.key.label
  1742.     { type$ "proceedings" =
  1743.     'editor.key.label            % apalike ignores organization
  1744.     'author.key.label            % for labeling and sorting
  1745.       if$
  1746.     }
  1747.   if$
  1748.   ", "                            % these three lines are
  1749.   *                            % for apalike, which
  1750.   year field.or.null purify$ #-1 #4 substring$        % uses all four digits
  1751.   *
  1752.   'label :=
  1753. }
  1754. % It doesn't seem like a particularly good idea to use an order-of-citation
  1755. % reference list when using alphabetic labels, but we need to have a
  1756. % special pass to calculate labels when this happens.
  1757. % When sorting, we compute the sortkey by executing "presort" on each entry.
  1758. % The presort key contains a number of "sortify"ed strings, concatenated
  1759. % with multiple blanks between them.  This makes things like "brinch  per"
  1760. % come before "brinch hansen  per".
  1761. %
  1762. % The fields used here are: the sort.label for alphabetic labels (as set by
  1763. % calc.label), followed by the author names (or editor names or organization
  1764. % (with a leading "The " removed) or key field, depending on entry type and on
  1765. % what's empty), followed by year, followed by the first bit of the title
  1766. % (chopping off a leading "The ", "A ", or "An ").
  1767. % Names are formatted: Von Last First Junior.
  1768. % The names within a part will be separated by a single blank
  1769. % (such as "brinch hansen"), two will separate the name parts themselves
  1770. % (except the von and last), three will separate the names,
  1771. % four will separate the names from year (and from label, if alphabetic),
  1772. % and four will separate year from title.
  1773. %
  1774. % The sort.format.names function takes an argument that should be in
  1775. % BibTeX name format, and returns a string containing "   "-separated
  1776. % names in the format described above.  The function is almost the same
  1777. % as format.names.
  1778. FUNCTION {sort.format.names}
  1779. { 's :=
  1780.   #1 'nameptr :=
  1781.   ""
  1782.   s num.names$ 'numnames :=
  1783.   numnames 'namesleft :=
  1784.     { namesleft #0 > }
  1785.     { nameptr #1 >
  1786.     { "   " * }
  1787.     'skip$
  1788.       if$                        % apalike uses initials
  1789.       s nameptr "{vv{ } }{ll{ }}{  f{ }}{  jj{ }}" format.name$ 't := % <= here
  1790.       nameptr numnames = t "others" = and
  1791.     { "et al" * }
  1792.     { t sortify * }
  1793.       if$
  1794.       nameptr #1 + 'nameptr :=
  1795.       namesleft #1 - 'namesleft :=
  1796.     }
  1797.   while$
  1798. }
  1799. % The sort.format.title function returns the argument,
  1800. % but first any leading "A "'s, "An "'s, or "The "'s are removed.
  1801. % The chop.word function uses s, so we need another string variable, t
  1802. FUNCTION {sort.format.title}
  1803. { 't :=
  1804.   "A " #2
  1805.     "An " #3
  1806.       "The " #4 t chop.word
  1807.     chop.word
  1808.   chop.word
  1809.   sortify
  1810.   #1 global.max$ substring$
  1811. }
  1812. % The auxiliary functions here, for the presort function, are analogous to
  1813. % the ones for calc.label; the same comments apply, except that the
  1814. % organization field takes precedence here over the key field.  For sorting
  1815. % purposes, we still remove a leading "The " from the organization field.
  1816. FUNCTION {author.sort}
  1817. { author empty$
  1818.     { key empty$
  1819.     { "to sort, need author or key in " cite$ * warning$
  1820.       ""
  1821.     }
  1822.     { key sortify }
  1823.       if$
  1824.     }
  1825.     { author sort.format.names }
  1826.   if$
  1827. }
  1828. FUNCTION {author.editor.sort}
  1829. { author empty$
  1830.     { editor empty$
  1831.     { key empty$
  1832.         { "to sort, need author, editor, or key in " cite$ * warning$
  1833.           ""
  1834.         }
  1835.         { key sortify }
  1836.       if$
  1837.     }
  1838.     { editor sort.format.names }
  1839.       if$
  1840.     }
  1841.     { author sort.format.names }
  1842.   if$
  1843. }
  1844. FUNCTION {editor.sort}
  1845. { editor empty$
  1846.     { key empty$
  1847.     { "to sort, need editor or key in " cite$ * warning$
  1848.       ""
  1849.     }
  1850.     { key sortify }
  1851.       if$
  1852.     }
  1853.     { editor sort.format.names }
  1854.   if$
  1855. }
  1856. %            apalike uses two sorting passes; the first one sets the
  1857. %            labels so that the `a's, `b's, etc. can be computed;
  1858. %            the second pass puts the references in "correct" order.
  1859. %            The presort function is for the first pass. It computes
  1860. %            label, sort.label, and title, and then concatenates.
  1861. FUNCTION {presort}
  1862. { calc.label
  1863.   label sortify
  1864.   "    "
  1865.   *
  1866.   type$ "book" =
  1867.   type$ "inbook" =
  1868.   or
  1869.     'author.editor.sort
  1870.     { type$ "proceedings" =
  1871.     'editor.sort
  1872.     'author.sort
  1873.       if$
  1874.     }
  1875.   if$
  1876.   #1 entry.max$ substring$    % for
  1877.   'sort.label :=        % apalike
  1878.   sort.label            % style
  1879.   *
  1880.   "    "
  1881.   *
  1882.   title field.or.null
  1883.   sort.format.title
  1884.   *
  1885.   #1 entry.max$ substring$
  1886.   'sort.key$ :=
  1887. }
  1888. ITERATE {presort}
  1889. % And now we can sort
  1890. SORT        % by label, sort.label, title---for final label calculation
  1891. % This long comment applies only to alphabetic labels, when sorted
  1892. %
  1893. % Now comes the final computation for alphabetic labels, putting in the 'a's
  1894. % and 'b's and so forth if required.  This involves two passes: a forward
  1895. % pass to put in the 'b's, 'c's and so on, and a backwards pass
  1896. % to put in the 'a's (we don't want to put in 'a's unless we know there
  1897. % are 'b's).
  1898. % We have to keep track of the longest (in width$ terms) label, for use
  1899. % by the "thebibliography" environment.
  1900. %
  1901. % VAR: longest.label, last.sort.label, next.extra: string
  1902. %      longest.label.width, last.extra.num: integer
  1903. %
  1904. % initialize.longest.label ==
  1905. %  BEGIN
  1906. %    longest.label := ""
  1907. %    last.sort.label := int.to.chr$(0)
  1908. %    next.extra := ""
  1909. %    longest.label.width := 0
  1910. %    last.extra.num := 0
  1911. %  END
  1912. %
  1913. % forward.pass ==
  1914. %  BEGIN
  1915. %    if last.sort.label = sort.label then
  1916. %        last.extra.num := last.extra.num + 1
  1917. %        extra.label := int.to.chr$(last.extra.num)
  1918. %    else
  1919. %        last.extra.num := chr.to.int$("a")
  1920. %        extra.label := ""
  1921. %        last.sort.label := sort.label
  1922. %    fi
  1923. %  END
  1924. %
  1925. % reverse.pass ==
  1926. %  BEGIN
  1927. %    if next.extra = "b" then
  1928. %        extra.label := "a"
  1929. %    fi
  1930. %    label := label * extra.label
  1931. %    if width$(label) > longest.label.width then
  1932. %        longest.label := label
  1933. %        longest.label.width := width$(label)
  1934. %    fi
  1935. %    next.extra := extra.label
  1936. %  END
  1937. STRINGS { last.label next.extra }    % apalike labels are only for the text;
  1938. INTEGERS { last.extra.num }        % there are none in the bibliography
  1939. FUNCTION {initialize.extra.label.stuff}    % and hence there is no `longest.label'
  1940. { #0 int.to.chr$ 'last.label :=
  1941.   "" 'next.extra :=
  1942.   #0 'last.extra.num :=
  1943. }
  1944. FUNCTION {forward.pass}
  1945. { last.label label =
  1946.     { last.extra.num #1 + 'last.extra.num :=
  1947.       last.extra.num int.to.chr$ 'extra.label :=
  1948.     }
  1949.     { "a" chr.to.int$ 'last.extra.num :=
  1950.       "" 'extra.label :=
  1951.       label 'last.label :=
  1952.     }
  1953.   if$
  1954. }
  1955. FUNCTION {reverse.pass}
  1956. { next.extra "b" =
  1957.     { "a" 'extra.label := }
  1958.     'skip$
  1959.   if$
  1960.   label extra.label * 'label :=
  1961.   extra.label 'next.extra :=
  1962. }
  1963. EXECUTE {initialize.extra.label.stuff}
  1964. ITERATE {forward.pass}
  1965. REVERSE {reverse.pass}
  1966. %                Now that the label is right we sort for real,
  1967. %                on sort.label then year then title.  This is
  1968. %                for the second sorting pass.
  1969. FUNCTION {bib.sort.order}
  1970. { sort.label
  1971.   "    "
  1972.   *
  1973.   year field.or.null sortify
  1974.   *
  1975.   "    "
  1976.   *
  1977.   title field.or.null
  1978.   sort.format.title
  1979.   *
  1980.   #1 entry.max$ substring$
  1981.   'sort.key$ :=
  1982. }
  1983. ITERATE {bib.sort.order}
  1984. SORT        % by sort.label, year, title---giving final bibliography order
  1985. % Now we're ready to start writing the .BBL file.
  1986. % We begin, if necessary, with a LaTeX macro for unnamed names in an alphabetic
  1987. % label; next comes stuff from the `preamble' command in the database files.
  1988. % Then we give an incantation containing the command
  1989. %     \begin{thebibliography}{...}
  1990. % where the `...' is the longest label.
  1991. %
  1992. % We also call init.state.consts, for use by the output routines.
  1993. FUNCTION {begin.bib}
  1994. { preamble$ empty$                % no \etalchar in apalike
  1995.     'skip$
  1996.     { preamble$ write$ newline$ }
  1997.   if$
  1998.   "\begin{thebibliography}{}" write$ newline$        % no labels in apalike
  1999. }
  2000. EXECUTE {begin.bib}
  2001. EXECUTE {init.state.consts}
  2002. % Now we produce the output for all the entries
  2003. ITERATE {call.type$}
  2004. % Finally, we finish up by writing the `\end{thebibliography}' command.
  2005. FUNCTION {end.bib}
  2006. { newline$
  2007.   "\end{thebibliography}" write$ newline$
  2008. }
  2009. EXECUTE {end.bib}
  2010.